package com.surfacing.rcp.model.codec;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;


import org.apache.log4j.Logger;

import com.surfacing.rcp.model.common.AbstractMessage;
import com.surfacing.rcp.model.entity.StatNaca;

public class StatNacaEncoder implements MessageEncoder {

	private static final Logger log = Logger.getLogger(StatNacaEncoder.class);

	@Override
	public void doEncode(AbstractMessage message, XMLStreamWriter writer)
			throws XMLStreamException {
		// Cast the object to a item
		StatNaca member = (StatNaca) message;

		// assert valid
		if (member == null) {
			log.warn("WARNING: Object StatNaca is null and cannot be encoded");
			return;
		}

		// start
		writer.writeStartElement(StatNaca.ID);

		// write the elements and attributes
		writer.writeStartElement("statName");
		writer.writeCharacters(member.getName());
		writer.writeEndElement();
		// get the encoder for the location
		// write the elements and attributes
		writer.writeStartElement("statAnzahl");
		writer.writeCharacters(member.getAnzahl());
		writer.writeEndElement();
		// write the elements and attributes
		// end
		writer.writeEndElement();
	}

}
